import { createRouter, createWebHashHistory } from 'vue-router'
import HomeView from '../views/home'
import ListView from '../views/list'
import DetailView from '../views/detail'
import About from '../views/about-us.vue'
// import Center from '../views/center.vue'
// import Share from '../views/share.vue'
// import Login from '../views/login'
// import SmsCode from '../views/login/sms'
// import Update from '../views/update'
// import Success from '../views/success'
// import Alipay from '../views/alipay'

import store from '@/store'
import { noop } from '@/utils'

const routes = [
	{
		path: '/',
		name: 'home',
		component: HomeView,
		meta: {
			title: ''
		}
	},
	{
		path: '/list',
		name: 'List',
		component: ListView,
		meta: {
			title: ''
		}
	},
	{
		path: '/detail',
		name: 'Detail',
		component: DetailView,
		meta: {
			title: ''
		}
	},
	{
		path: '/about',
		name: 'About',
		component: About,
		meta: {
			title: '联系咨询	'
		}
	}
]

const router = createRouter({
	history: createWebHashHistory(),
	routes
})

const whiteList = ['/login', '/smsCode']

router.beforeEach(async (to, from, next) => {
	// if (to.query.distributorId && !whiteList.includes(to.path)) {
	// 	localStorage.clear()
	// 	next('/login?distributorId=' + to.query.distributorId)
	// }

	// if (whiteList.includes(to.path)) {
	// 	next()
	// 	return
	// }

	// const { userInfo, token } = store.getters
	// if (!userInfo && token) {
	// 	await store.dispatch('getUserInfo').catch(noop)
	// }
	// if (!store.getters.userInfo) {
	// 	next('/login')
	// } else {
	// 	to.path == '/login' ? next('/') : next()
	// }

	next()
})

router.afterEach((to) => {
	// if (!whiteList.includes(to.path) && !store.getters.userInfo.name) {
	// 	store.dispatch('showUserForm')
	// }
	sensors.quick('autoTrackSinglePage')
})

export default router
